package com.m3958.firstgwt.server.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.inject.Singleton;

import clojure.lang.RT;
import clojure.lang.Var;

@Singleton
public class ClojureServlet  extends HttpServlet{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private boolean cloaded = false; 

	@Override
	public void doGet(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		doPost(req, res);
	}
	
	@Override
	public void doPost(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		if(!cloaded){
			RT.loadResourceScript("com/m3958/firstgwt/server/servlet/ClojureServlet.clj");
			cloaded = true;
		}
		Var do_fetch = RT.var("com.m3958.firstgwt.server.servlet.ClojureServlet", "foo");
		System.out.println(do_fetch.invoke("a","b"));
	}
}
